const express = require('express')
const cors = require('cors')
const fs = require('fs')
const app = express()

app.use(cors({
    credentials:true,
    optionsSu :200,
    origin: 'http://127.0.0.1:5500'
}));
//http://127.0.0.1:3000/user
app.get('/user',(request,response)=>{
    const user = {name:'cj',age:20}
    //读取指定路径的文件
    fs.readFile('./new_avatar.jpg',(err,data) =>{
        if(err){
            response.sendStatus(500)//发送错误，默认500
        }else{
           user.avatar = data.toString('base64')//字符串形式导出文件 
           response.send(user)
        }
    })
    //response.send(user)
})
app.listen(3000,function(){
    console.log('serve started at http://127.0.0.1:3000');
})